
'HongShijin 
'me@hongshijin.com 
'2017/05/11 17:05:03 
'Batch change [AssemblyInfo.cs]'s [AssemblyVersion] and [AssemblyFileVersion] as now

Option Explicit 

Const ForReading = 1 
Const ForWriting = 2 

Function EachFolder (cd, folder) 
	Dim d, t, f, s, r 

	For Each f In folder.Files 
		If f.Name = "AssemblyInfo.cs" Then 
			Set s = CreateObject("ADODB.Stream") 
			s.Type = 2 
			s.Mode = 3 
			s.CharSet = "UTF-8" 
			s.Open 
			s.LoadFromFile f 
			t = s.ReadText 
			Set r = new RegExp 
			r.Global = True 
			r.IgnoreCase = True 
			d = Now() 
			r.Pattern = "(\[assembly:[\s]*AssemblyVersion\(""\d+)\.\d+\.\d+\.[\d\*]+(""\)\])" 
			t = r.Replace(t, "$1." & Right("0" & (Year(d) Mod 100), 2) & "." & Month(d) & Right("0" & (Day(d) Mod 100), 2) & ".*$2") 
			r.Pattern = "(\[assembly:[\s]*AssemblyFileVersion\("")\d+\.\d+\.\d+\.[\d\*]+(""\)\])" 
			t = r.Replace(t, "$1" & (Year(d) Mod 100) & "." & Month(d) & "." & (Day(d) Mod 100) & "." & Hour(d) & Right("0" & (Minute(d) Mod 100), 2) & "$2") 
			s.Position = 0 
			s.WriteText t 
			s.SetEOS 
			t = f.Path 
			f.delete 
			s.SaveToFile t 
			s.Close 
			EachFolder = Replace(Right(f, Len(f) - Len(cd) - 1), "\Properties\AssemblyInfo.cs", "") 
			Exit Function 
		End If 
	Next 

	EachFolder = "" 
	For Each f In folder.SubFolders 
		t = EachFolder(cd, f) 
		If t <> "" And Len(t) > 1 Then EachFolder = EachFolder & VbCrLf & t 
	Next 
End Function 

Dim fso, vbs, cd, t 
IF WScript.Arguments.Count > 0 THEN 
	t = WScript.Arguments(0) 
Else 
	t = Wscript.ScriptFullName 
End IF 
If t = "" Then t = Wscript.ScriptFullName 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set vbs = fso.GetFile(t) 
Set cd = vbs.ParentFolder 
t = EachFolder(cd, cd) 
Wscript.Echo t 
